//--------------------------------------------------------------
//
// Qizhi Zhang 
// ezhung@gmail.com
// http://www.moorwind.com
//
//--------------------------------------------------------------
package reader.controller
{
	import mx.controls.Alert;
	import mx.events.CloseEvent;
	
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	
	import reader.core.UserConfirmCommandConfig;

	public class UserConfirmCommand extends SimpleCommand implements ICommand
	{
		////////////////////////////////////////////////////////////////////////////////
		//private variables
		private var callback:Function;
		
		//////////////////////////////////////////////////////////////////////////////
		//methods
		
		override public function execute(notification:INotification):void
		{
			var config:UserConfirmCommandConfig = notification.getBody() as UserConfirmCommandConfig;
			callback = config.callback;
			
			Alert.yesLabel = config.yesLabel;
			Alert.cancelLabel = config.cancelLabel;
			var alert:Alert = Alert.show(config.message, config.title, Alert.OK | Alert.CANCEL, config.parent, onDoDelete_handler);
			alert.maxWidth = config.maxWidth;
			alert.maxHeight = config.maxHeight;
			alert.setStyle("paddingBottom", 5);
		}
		
		private function onDoDelete_handler(e:CloseEvent):void
		{
			if (e.detail==Alert.OK) 
			{
				callback();
			}
		}
		
	}
}